/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cda.splashScreen;

import cda.ScreenConvert.ConvertionScreen;
import cda.splash.MainActivity;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

/**
 *
 * @author Shyzkanza
 */
public class ScreenAnimation implements ApplicationListener {
    
    private final static int        LARGEUR = 0;
    private final static int        HAUTEUR = 1;

    private SpriteBatch             _batch;
    
    // Gestion des chaines de caracteres
    private CharSequence            _str3;
    private BitmapFont              _fontTitre3;
    
    private Texture                 _texture;
    private Sprite                  _sprite;
    
    private float                   _color1 = 0f;
    private float                   _color2 = 0f;
    private float                   _color3 = 0f;
    private int                     _etape = 0;
    private int                     _compteur = 0;
    
    // Convertion des unites de longueurs
    private ConvertionScreen        _converteur;
    private int[][]                 _listePoucentage = new int[100][2];
    
    public void create() {
        _batch = new SpriteBatch();
        _texture = new Texture(Gdx.files.internal("canard.png"));
        _converteur = new ConvertionScreen(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        initMesure();
        _str3 = "Coin Dev Art";
        _fontTitre3 = new BitmapFont(Gdx.files.internal("data/Grungy32.fnt"),Gdx.files.internal("data/Grungy32.png"), false);
        _fontTitre3.setColor(Color.RED);
        _sprite = new Sprite(_texture, 0, 0, 128, 128);
        _sprite.setPosition(_listePoucentage[_converteur.getWidthPoucent((Gdx.graphics.getWidth()/2)-64)][LARGEUR], _listePoucentage[60][HAUTEUR]);
        _sprite.setColor(1, 1, 1, 1);
        Gdx.gl.glClearColor(_color1, _color1, _color1, 0f);
    }

    public void resize(int i, int i1) {
        
    }

    public void render() {
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // This cryptic line clears the screen.      
        Gdx.gl.glClearColor(_color1, _color1, _color1, 0f);
        
        if(_color1 < 1f && _etape == 0){
            _color1 += 0.005f;
        }else if(_etape == 0){
            _etape = 1;
        }
        
        if((_color2+0.006f) < 1f && _etape == 1){
            _color2 += 0.005f;
            _color3 += 0.005f;
        }else if(_etape == 1){
            _etape = 2;
        }
        
        if (_compteur < 200 && _etape == 2){
            _compteur++;
        }else if(_etape == 2){
            _etape = 3;
        }
        
        if((_color2 - 0.005f) > 0f && _etape == 3){
            _color2 -= 0.005f;
        }
        
        if((_color1 - 0.005f) > 0f && _etape == 3){
            _color1 -= 0.005f;
        }else if(_etape == 3){
            _color1 -= 0.005f;
            _etape = 4;
        }
        
        _batch.begin();
        
        //_batch.setColor(255f, 255f, 255f, 0f);
        
        
        drawFront();
        _sprite.setColor(1f, 1f, 1f, _color2);
        
        _sprite.draw(_batch);
       
        _batch.end();
    }

    public void pause() {
        
    }

    public void resume() {
        
    }

    public void dispose() {
        
    }
    
    private void drawFront(){
        _fontTitre3.setColor(0f, 0f, 0f, _color3);
        
        if(MainActivity.PORTRAIT){
            _fontTitre3.draw(_batch, _str3, _listePoucentage[18][LARGEUR], _listePoucentage[63][HAUTEUR]);
        }else{
            _fontTitre3.draw(_batch, _str3, _listePoucentage[30][LARGEUR], _listePoucentage[70][HAUTEUR]);
        }
    }
    
    private void initMesure(){
        for (int i = 0; i < 100; i++) {
            _listePoucentage[i][0] = _converteur.getWidthPixel(i);
            _listePoucentage[i][1] = _converteur.getHeidthPixel(i);
        }
    }
}
